[C]Dynamic allocation memory of structure, related to GTK
Posted
by
MakeItWork
on Stack Overflow
See other posts from Stack Overflow
or by MakeItWork
Published on 2011-01-09T20:31:05Z
Indexed on
2011/01/09
20:53 UTC
Read the original article
Hit count: 153
Hello, I have following structure:
typedef struct
{
GtkWidget* PoziomaLinijka;
GtkWidget* PionowaLinijka;
GtkWidget* Label1;
GtkWidget* Label2;
gint x,y;
} StrukturaDrawing;
And i need to allocate it on the heap because later I have functions which uses that structure and I don't want to use global variables. So I allocate it like this:
StrukturaDrawing* Wsk;
Wsk = (StrukturaDrawing*)malloc(sizeof(StrukturaDrawing));
if (!Wsk)
{
printf("Error\n");
}
And it doesn't returning error and also works great with other functions, it works the way I wanted it to work so finally i wanted to free that memory and here is problem because in Debug Mode compilator bitches:
First-chance exception at 0x102d12b4 in GTK.exe: 0xC0000005: Access violation reading location 0xfffffffc. Unhandled exception at 0x102d12b4 in GTK.exe: 0xC0000005: Access violation reading location 0xfffffffc.
I connect callback to my function, like that:
g_signal_connect(G_OBJECT(Okno), "destroy", G_CALLBACK(Wyjscie), Wsk);
Function which is suppose to free memory and close program:
void Wyjscie(GtkWindow* window, GdkEvent* event, StrukturaDrawing* data)
{
gtk_main_quit();
free(data);
data = NULL;
}
Any help really appreciated.
© Stack Overflow or respective owner